package com.aglhz.nature.adapter;

import java.util.List;

import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aglhz.nature.R;
import com.aglhz.nature.ListView.MyGridView;
import com.aglhz.nature.adapter.HomeRecommendAdapter.ViewHolder;
import com.aglhz.nature.modle.item.ColumnsListData;
import com.aglhz.nature.modle.item.RecommendData;
import com.aglhz.nature.modle.item.classification.ListData;
import com.squareup.picasso.Picasso;

public class SecClassificationListAdapter extends BaseAdapter{
	public List<ListData> mData;
    public Context context;
	public SecClassificationListAdapter(List<ListData> mData, Context context) {
		super();
		this.mData = mData;
		this.context = context;
	} 
    
	    @Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mData.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return mData.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(final int  position, View convertView, ViewGroup arg2) {
			 ViewHolder viewHolder; 
				if(null==convertView){			
					  convertView = LayoutInflater.from(context).inflate(R.layout.item_secclass_listview, null); 
					  viewHolder = new ViewHolder();
					  viewHolder.relativelayout=(RelativeLayout) convertView.findViewById(R.id.relativelayout);
					  viewHolder.second_cla_iv= (ImageView) convertView.findViewById(R.id.second_cla_iv); 
					  viewHolder.goodsName = (TextView) convertView.findViewById(R.id.goodsName); 
					
					  viewHolder.second_cla_tvMoney = (TextView) convertView.findViewById(R.id.second_cla_tvMoney); 
					  
					  convertView.setTag(viewHolder); 
				}else{
					viewHolder = (ViewHolder) convertView.getTag(); 
				}
//				//设置图片
//				LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);  
//				lp.setMargins((int)(getScreenWidth()*0.025), (int)(getScreenWidth()*0.025), (int)(getScreenWidth()*0.025), (int)(getScreenWidth()*0.025));		
//				viewHolder.second_cla_iv.setLayoutParams(lp); 
				//设置图片
				
					  String url = mData.get(position).getGoodsImgCover();
					//picasso加载网络图片
					   Picasso.with(context)  
					   .load(url)  	 
					    .resize(getScreenWidth(), getScreenWidth()*2/5)
					   .into(viewHolder.second_cla_iv) ;
					   //
					   viewHolder.goodsName.setText(mData.get(position).getGoodsName());
					
						viewHolder.second_cla_tvMoney.setText(mData.get(position).getPrice()); 
				 int screenWidth = getScreenWidth();
					ListView.LayoutParams p=new ListView.LayoutParams(screenWidth,screenWidth);
					convertView.setLayoutParams(p);
				return convertView;
			}
			class ViewHolder 
			{   
				 public ImageView second_cla_iv; 
				    public TextView goodsName;
				    public RelativeLayout relativelayout;
				    public TextView second_cla_tvMoney;
			} 
			
			/**
			 * 获取屏幕宽度
			 * 
			 * @return
			 */
			protected int getScreenWidth() {
				WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
				Display display = wm.getDefaultDisplay();
				return display.getWidth();
			}
}
